<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-everydayMenu-edit" th:object="${everydayMenu}">
            <input id="dailyId" name="dailyId" th:field="*{dailyId}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">日期：</label>
                <div class="col-sm-8">
                    <input id="dailyDate" name="dailyDate" th:field="*{dailyDate}" class="form-control" type="text" readonly="true">
                </div>
            </div>
            <!-- <div class="form-group">	
                <label class="col-sm-3 control-label">今天是否开餐</label>
                <div class="col-sm-8">
				    <div class="radio-box" th:each="dict : ${@dict.getType('daily_is_open')}">
						<input type="radio" th:id="${dict.dictCode}" name="isOpen" th:value="${dict.dictValue}" th:field="*{isOpen}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
            </div> -->
            <div class="form-group">
				<label class="col-sm-3 control-label">今天是否开餐：</label>
				<div class="col-sm-8">
					<select id="isOpen" name="isOpen" class="form-control m-b">
						<option value="0" th:field="*{isOpen}">不开餐</option>
						<option value="1" th:field="*{isOpen}">开餐</option>
					</select>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 选择开餐时，请选择菜单</span>
				</div>
			</div>
            <div class="form-group" id="selectMenu" style="display: none">
				<label class="col-sm-3 control-label">选择菜单：</label>
				<div class="col-sm-8">
					<select id="menuId" name="menuId" class="form-control select2-hidden-accessible">
						<option th:each="menu:${menus}" th:value="${menu.menuId}" th:text="${menu.menuName}" th:field="*{menuId}" th:disabled="${menu.status == '1'}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
    
    	/* Date.prototype.Format = function (fmt) { 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        	return fmt;
    	}  */
    	
    	$(function() {
 			$("#isOpen").change();
 	    });
    	
    	$("#form-everydayMenu-edit").validate({
			submitHandler:function(form){
				edit();
			}
		});
    	
    	function edit() {
            var dailyId = $("input[name='dailyId']").val();
            var isOpen = $("#isOpen").val();
            var menuId = $("#menuId").val();
            var dailyDate = $("input[name='dailyDate']").val();
            
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "dailymenu/everyday/edit",
				data : {
					"dailyId": dailyId,
					"isOpen": isOpen,
					"menuId": menuId
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.saveSuccess(data);
					/* if (data.code == 0) {
						$.table._option.url = ctx + "dailymenu/everyday/listMonth?year="+2019+"&month="+2;
	    		        $.table.refresh();
	    		        $.modal.close();
					} */
					
					/* if (data.code == web_status.SUCCESS) {
	                	$.modal.msgSuccess(data.msg);
	            		$.table.refresh();
	                } else {
	                	$.modal.alertError(data.msg);
	                }
	            	$.modal.closeLoading(); */
	            	
	            	/* data.url = ctx + "dailymenu/everyday/listMonth?year="+2019+"&month="+2;
	            	$.operate.saveSuccess(data); */
					
    		       		
					/* if (data.code == 0) {
            			$.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
            			$.table._option.url = ctx + "dailymenu/everyday/listMonth?year="+2019+"&month="+2;
    		       		$.table.refresh();
	                } else {
	                	$.modal.alertError(data.msg);
	                }
	            	$.modal.closeLoading(); */
	            	
					//testhtml();
				}
			});
		}
    	
    	$("#isOpen").change(function(event){
        	var isOpen = $(event.target).val();
        	isOpenVisible(isOpen);
        });
		
		function isOpenVisible(isOpen) {
			if (isOpen == 1) {
	    		$("#selectMenu").show();
	    	} else {
	    		$("#selectMenu").hide();
	    	}
		}
		
		function testhtml() {
            alert(123);
			$.table._option.url = prefix + "/listMonth?year="+2019+"&month="+2;
       		$.table.refresh();
        }
    
	</script>
</body>
</html>
